package com.fangtao.dao;

import com.fangtao.domain.User;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @ClassName UserDAO
 * @Description TODO
 * @date 2022/9/22 14:04
 * @author: fangtao
 * @Version 1.0
 */
public class UserDAO extends BasicDAO<User>{
    //添加usedao的特殊操作，输入user类，将其转存到数据库中
    public int add(User user){
        int updateRows = 0;
        if(null != user){
            String sql = "insert into smbms_user (userCode,userName,userPassword," +
                    "userRole,gender,birthday,phone,address,creationDate,createdBy) " +
                    "values(?,?,?,?,?,?,?,?,?,?)";
            Object[] params = {user.getUserCode(),user.getUserName(),user.getUserPassword(),
                    user.getUserRole(),user.getGender(),user.getBirthday(),
                    user.getPhone(),user.getAddress(),user.getCreationDate(),user.getCreatedBy()};

            updateRows = this.update(sql, params);
        }
        return updateRows;

   }
//   根据id来修改用户数据
public int modify(Connection connection, User user){

    int flag = 0;

    if(null != user){
        String sql = "update smbms_user set userName=?,"+
                "gender=?,birthday=?,phone=?,address=?,userRole=?,modifyBy=?,modifyDate=? where id = ? ";
        Object[] params = {user.getUserName(),user.getGender(),user.getBirthday(),
                user.getPhone(),user.getAddress(),user.getUserRole(),user.getModifyBy(),
                user.getModifyDate(),user.getId()};
        flag = this.updateFile(connection,sql, params);
    }
    return flag;
}
}
